<?php
/**
 * 页面控制器
 *
 * @package    app
 * @version    1.0
 * @author     Ray 33705910@qq.com
 * @license    MIT License
 * @copyright  2013 - 2015 Ray
 * @link       http://wangxiaolei.cn
 */

/**
 * 本控制器主要用于：
 * 1.
 * @package  app
 * @extends  Controller
 */
namespace web;

class Controller_Page extends Controller_BaseController {

    public $template = "template";

    public function before(){
        parent::before();
        
        $seller = \Session::get('seller');
        $main_menu_id = \Input::get('m',$seller->main_menu);//主导航大类菜单ID
        $left_menu_id = \Input::get('l',$seller->article_menu);//左侧导航大类菜单ID
        $bottom_menu_id = \Input::get('b',$seller->bottom_menu);//底部导航大类菜单ID
        $current_menu_id = \Input::get('c',0);//

        $menu_root = \Model_Category::find($current_menu_id);
        $params['current_menu'] = $menu_root;//面包屑   首页>parent>current

        //主菜单
        $menu_root = \Model_Category::find($main_menu_id);
        $menu = $menu_root->children()->get();
        $items = array();
        if($menu){
            $items = \utils\CategoryHandler::get_children($menu);
        }

        $params['nav_menu'] = $items;
        unset($menu_root);
        unset($menu);

        //左侧菜单
        $menu_root = \Model_Category::find($left_menu_id);
        $params['left_menu'] = $menu_root;//左侧菜单
        $menu = $menu_root->children()->get();
        $items = array();
        if($menu){
            $items = \utils\CategoryHandler::get_children($menu);
        }
        $params['left_menus'] = $items;
        unset($menu_root);
        unset($menu);

        //底部菜单
        $menu_root = \Model_Category::find($bottom_menu_id);
        $left_menu = $menu_root->children()->get();

        //组合2-3级菜单
        $items = array();
        if($left_menu){
            $items = \utils\CategoryHandler::get_children($left_menu);
        }
        $params['bottom_menu'] = $items;
        \View::set_global($params);
    }

    public function action_index($id=0){
        $params = array(
            'title' => '联系我们'
        );

        $page = \Input::get('cat','contact');
        $item = \Model_Node::find($id);
		$params['item'] = $item;

        \View::set_global($params);
        $this->template->content = \View::forge("{$page}");
    }
}